package com.kmxd.ams.app.search.command;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kmxd.ams.client.archive.*;
import com.kmxd.ams.client.archive.vo.ArchiveAuthScopeVO;
import com.kmxd.ams.client.search.vo.SearchAuthVO;
import com.kmxd.ams.client.system.ISysCropSvc;
import com.kmxd.ams.client.system.ISysUserSvc;
import com.kmxd.ams.client.system.vo.SysUserVO;
import com.kmxd.ams.client.use.IUseArchSvc;
import com.kmxd.ams.client.use.IUseOrderSvc;
import com.kmxd.ams.client.use.IUsePushSvc;
import com.kmxd.ams.client.use.dto.UseArchQueryDTO;
import com.kmxd.ams.client.use.dto.UsePushAuthQueryDTO;
import com.kmxd.ams.client.use.vo.UseArchListVO;
import com.kmxd.ams.core.common.constant.ArchConst;
import com.kmxd.ams.core.common.constant.ArchControlConst;
import com.kmxd.ams.core.common.enums.*;
import com.kmxd.ams.core.util.ConvertUtil;
import com.kmxd.ams.core.util.SecurityUtil;
import com.kmxd.ams.infra.arrange.base.SystemBO;
import com.kmxd.ams.infra.search.entity.DocumentEs;
import com.kmxd.ams.infra.use.entity.UseOrder;
import java.util.*;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 权限控制模块
 *
 * @author zuolg
 */
@Slf4j
@Component
@AllArgsConstructor
public class CommonAuthCmd {
  private final ISysCropSvc sysCropSvc;
  private final IArchiveAuthSvc authSvc;
  private final SpecialAuthCmd specialAuthCmd;
  private final ISysUserSvc sysUserSvc;

  /**
   * 获取权限
   *
   * @param archTypeId
   * @param doc
   * @param type
   * @return
   */
  public SearchAuthVO getAuth(Long archTypeId, SystemBO doc) {
    doc.setArchTypeId(archTypeId);
    SearchAuthVO searchAuth = getSearchAuth(archTypeId, doc);
    SearchAuthVO pushAuth = getPushAuth(doc, SecurityUtil.getUserId());
    SearchAuthVO authVO = mergeAuth(searchAuth, pushAuth);
    authVO.setOnlineBrowser(
        BooleanUtil.isTrue(authVO.getBrowserFile()) ? Boolean.TRUE : authVO.getOnlineBrowser());
    // 判断当前用户是否有浏览权限，有直接返回
    SysUserVO userVO = sysUserSvc.view(SecurityUtil.getLoginUser().getSysUser().getId());

    // 仅开放档案
    if (ObjectUtil.equals(userVO.getTextBrowsing(), 2)
            && ObjectUtil.equals(doc.getControlIdentifier(), ArchControlConst.CTL_2)) {
      authVO.setOnlineBrowser(Boolean.TRUE);
      authVO.setBrowserFile(Boolean.TRUE);
    }

    return authVO;
  }

  /**
   * 获取推送权限
   *
   * @param doc
   * @return
   */
  private SearchAuthVO getPushAuth(SystemBO doc, Long userId) {
    // 特殊利用权限已经通过,直接返回
    IUsePushSvc usePushSvc = SpringUtil.getBean(IUsePushSvc.class);
    UsePushAuthQueryDTO qryAuth = BeanUtil.copyProperties(doc, UsePushAuthQueryDTO.class);
    qryAuth.setUserId(userId);
    SearchAuthVO auth = usePushSvc.getAuth(qryAuth);
    return auth;
  }

  /**
   * 检索相关权限获取
   *
   * @param archTypeId
   * @param doc
   * @return
   */
  public SearchAuthVO getSearchAuth(Long archTypeId, SystemBO doc) {
    SearchAuthVO auth =Optional.ofNullable( getApplyAuthInfo(doc)).orElse(new SearchAuthVO());

    // 查询门类通用权限
    ArchiveAuthScopeVO authVO = authSvc.getByArchTypeId(archTypeId);
    if (ObjectUtil.isNotNull(authVO)) {
      SearchAuthVO authScope = getAuthScope(doc, authVO);
      auth = mergeAuth(auth, authScope);
    }
    // 校验特殊权限
    specialAuthCmd.getSpecialAuth(archTypeId, doc, auth);

    return auth;
  }

  /**
   * 权限校验
   *
   * @param archTypeId
   * @param doc
   * @return
   */
  public boolean checkAuth(Long archTypeId, DocumentEs doc, UseTypeEnum useTypeEnum) {
    // 判断当前用户是否有浏览权限，有直接返回
    SysUserVO userVO = sysUserSvc.view(SecurityUtil.getLoginUser().getSysUser().getId());
    if (ObjectUtil.isNotEmpty(userVO)
        && ObjectUtil.equals(userVO.getTextBrowsing(), 1)
        && (ObjectUtil.equals(UseTypeEnum.ONLINE_BROWSER.getType(), useTypeEnum.getType())
            || ObjectUtil.equals(UseTypeEnum.BROWSER_FILE.getType(), useTypeEnum.getType()))) {
      return true;
    }

    // 仅开放档案
    if (ObjectUtil.equals(userVO.getTextBrowsing(), 2)
        && ObjectUtil.equals(doc.getControlIdentifier(), ArchControlConst.CTL_2)) {
      return true;
    }

    boolean pushAuth = checkPushAuth(doc, useTypeEnum, SecurityUtil.getUserId());
    if (pushAuth) {
      return pushAuth;
    }

    boolean applyAuth = checkApplyAuth(doc, useTypeEnum);
    if (applyAuth) {
      return applyAuth;
    }
    ArchiveAuthScopeVO authVO = authSvc.getByArchTypeId(archTypeId);

    if (Objects.isNull(authVO)) {
      return false;
    }
    // 判断特殊权限
    return specialAuthCmd.checkSpecialAuth(archTypeId, doc, useTypeEnum);
  }

  public boolean checkApplyAuth(DocumentEs doc, UseTypeEnum useTypeEnum) {
    SearchAuthVO applyAuth = getApplyAuthInfo(doc);
    if (ObjectUtil.isNull(applyAuth)) {
      return false;
    }
    switch (useTypeEnum) {
      case ONLINE_BROWSER:
        return BooleanUtil.isTrue(applyAuth.getOnlineBrowser());
      case BROWSER_FILE:
        return BooleanUtil.isTrue(applyAuth.getBrowserFile());
      case ONLINE_PRINT:
        return BooleanUtil.isTrue(applyAuth.getOnlinePrint());
      case DOWNLOAD:
        return BooleanUtil.isTrue(applyAuth.getDownload());
      case DOWNLOAD_SOURCE:
        return BooleanUtil.isTrue(applyAuth.getDownloadSource());
      case LIVE_READ:
        return BooleanUtil.isTrue(applyAuth.getLiveRead());
      case LEND_OUT:
        return BooleanUtil.isTrue(applyAuth.getLendOut());
      case COPY_SEND:
        return BooleanUtil.isTrue(applyAuth.getCopySend());
      case EXTRACT:
        return BooleanUtil.isTrue(applyAuth.getExcerpt());
      default:
        return false;
    }
  }

  public boolean checkPushAuth(DocumentEs doc, UseTypeEnum useTypeEnum, Long userId) {
    SearchAuthVO applyAuth = getPushAuth(doc, userId);
    if (ObjectUtil.isNull(applyAuth)) {
      return false;
    }
    switch (useTypeEnum) {
      case ONLINE_BROWSER:
        return BooleanUtil.isTrue(applyAuth.getOnlineBrowser());
      case BROWSER_FILE:
        return BooleanUtil.isTrue(applyAuth.getBrowserFile());
      case ONLINE_PRINT:
        return BooleanUtil.isTrue(applyAuth.getOnlinePrint());
      case DOWNLOAD:
        return BooleanUtil.isTrue(applyAuth.getDownload());
      case DOWNLOAD_SOURCE:
        return BooleanUtil.isTrue(applyAuth.getDownloadSource());
      case LIVE_READ:
        return BooleanUtil.isTrue(applyAuth.getLiveRead());
      case LEND_OUT:
        return BooleanUtil.isTrue(applyAuth.getLendOut());
      case COPY_SEND:
        return BooleanUtil.isTrue(applyAuth.getCopySend());
      case EXTRACT:
        return BooleanUtil.isTrue(applyAuth.getExcerpt());
      default:
        return false;
    }
  }

  /**
   * 获取利用申请权限
   *
   * @param doc
   * @return
   */
  public SearchAuthVO getApplyAuthInfo(SystemBO doc) {
    // 特殊利用权限已经通过,直接返回
    IUseOrderSvc useOrderSvc = SpringUtil.getBean(IUseOrderSvc.class);

    IUseArchSvc useArchSvc = SpringUtil.getBean(IUseArchSvc.class);
    UseArchQueryDTO qryArch = new UseArchQueryDTO();
    qryArch.setTableId(doc.getTableId());
    qryArch.setArchId(ConvertUtil.getValue(doc, ArchConst.DEF_ID, Long.class));
    qryArch.setUserId(SecurityUtil.getUserId());
    List<UseArchListVO> archList = useArchSvc.selectList(qryArch);
    if (ObjectUtil.isEmpty(archList)) {
      return null;
    }
    List<Long> orderIds =
        archList.stream().map(UseArchListVO::getOrderId).collect(Collectors.toList());
    List<UseOrder> orders =
        useOrderSvc.list(
            Wrappers.<UseOrder>lambdaQuery()
                .in(UseOrder::getId, orderIds)
                .orderByDesc(UseOrder::getCreateTime));
    if (ObjectUtil.isEmpty(orders)) {
      return null;
    }
    SearchAuthVO authVO = new SearchAuthVO();
    Boolean haveAuth = false;
    for (UseOrder order : orders) {
      if (ObjectUtil.notEqual(order.getEntType(), UseOrderTypeEnum.ELECTRONIC_USE.getCode())) {
        continue;
      }

      boolean pass = ObjectUtil.equals(order.getStatus(), UseOrderStatusEnum.PASSED.getCode());
      if (ObjectUtil.isEmpty(order.getOpTime()) || ObjectUtil.isEmpty(order.getPeriod())) {
        continue;
      }

      DateTime expirationTime =
          DateUtil.offsetDay(order.getOpTime(), Integer.parseInt(order.getPeriod()));
      boolean after = expirationTime.after(new Date());
      // 当前操作时间未超过到期时间，则有权限
      if (pass && after) {
        Boolean download = order.getDownload();
        boolean haveDownloadNum =
            Optional.ofNullable(order.getDownloadNumber()).orElse(0)
                > Optional.ofNullable(order.getDownloadCompletesysNumber()).orElse(0);
        if (BooleanUtil.isTrue(download) && haveDownloadNum) {
          authVO.setDownload(download);
          haveAuth = true;
        }
        if (BooleanUtil.isTrue(order.getDownloadSource()) && haveDownloadNum) {
          authVO.setDownloadSource(true);
          haveAuth = true;
        }
        if (BooleanUtil.isTrue(order.getOnlineBrowser())) {
          authVO.setOnlineBrowser(true);
          haveAuth = true;
        }
        if (BooleanUtil.isTrue(order.getBrowserFile())) {
          authVO.setBrowserFile(true);
          haveAuth = true;
        }
        if (BooleanUtil.isTrue(order.getOnlinePrint())) {
          authVO.setOnlinePrint(true);
          haveAuth = true;
        }
        if (BooleanUtil.isTrue(order.getExcerpt())) {
          authVO.setExcerpt(true);
          haveAuth = true;
        }
        if (BooleanUtil.isTrue(order.getDownload())) {
          authVO.setDownload(true);
          haveAuth = true;
        }
      }
    }
    // 有利用申请权限
    if (BooleanUtil.isTrue(haveAuth)) {
      return authVO;
    }
    return null;
  }

  /**
   * 按通用权限，检测权限
   *
   * @param doc
   * @param authVO
   * @return
   */
  private SearchAuthVO getAuthScope(SystemBO doc, ArchiveAuthScopeVO authVO) {
    // 知悉范围内
    SearchAuthVO searchAuthVO = getInDeptAuth(doc, authVO);

    // 知悉范围外权限
    getOutDeptAuth(doc, authVO, searchAuthVO);

    // 通用利用权限
    getOtherFondsAuth(doc, authVO, searchAuthVO);
    return searchAuthVO;
  }

  private SearchAuthVO getInDeptAuth(SystemBO doc, ArchiveAuthScopeVO authVO) {
    //    知悉范围外，返回空
    if (checkNotInDept(doc, authVO)) {
      return new SearchAuthVO();
    }

    return BeanUtil.copyProperties(authVO, SearchAuthVO.class);
  }
  /**
   * 知悉范围外权限
   *
   * @param doc 档案
   * @param authVO 权限
   * @param searchAuthVO 利用方式
   * @return
   */
  private void getOutDeptAuth(SystemBO doc, ArchiveAuthScopeVO authVO, SearchAuthVO searchAuthVO) {
    // 知悉范围外
    // 全宗不一致，直接返回 无知悉范围外权限
    if (ObjectUtil.notEqual(doc.getFondsId(), SecurityUtil.getFondsId())) {
      return;
    }
    // 知悉范围按部门划分, 档案部门与当前用户部门相同，无知悉范围外权限，直接返回无权限
    if (BooleanUtil.isTrue(authVO.getAuthDepartment())
        && ObjectUtil.equals(doc.getDepartmentId(), SecurityUtil.getSysUser().getDeptId())) {
      return;
    }
    // 知悉范围按创建人划分，创建人与当前用户相同，无知悉范围外权限，直接返回无权限
    //    if (BooleanUtil.isTrue(authVO.getAuthUser())
    //        && ObjectUtil.equals(doc.getCreateBy(), SecurityUtil.getSysUser().getDeptId())) {
    //      return;
    //    }
    if (BooleanUtil.isTrue(authVO.getOutOnlineBrowser())
        || BooleanUtil.isTrue(searchAuthVO.getOnlineBrowser())) {
      searchAuthVO.setOnlineBrowser(true);
    }
    if (BooleanUtil.isTrue(authVO.getOutBrowserFile())
        || BooleanUtil.isTrue(searchAuthVO.getBrowserFile())) {
      searchAuthVO.setBrowserFile(true);
    }
    if (BooleanUtil.isTrue(authVO.getOutOnlinePrint())
        || BooleanUtil.isTrue(searchAuthVO.getOnlinePrint())) {
      searchAuthVO.setOnlinePrint(true);
    }
    if (BooleanUtil.isTrue(authVO.getOutDownload())
        || BooleanUtil.isTrue(searchAuthVO.getDownload())) {
      searchAuthVO.setDownload(true);
    }

    if (BooleanUtil.isTrue(authVO.getOutDownloadSource())
        || BooleanUtil.isTrue(searchAuthVO.getDownloadSource())) {
      searchAuthVO.setDownloadSource(true);
    }
    if (BooleanUtil.isTrue(authVO.getOutLiveRead())
        || BooleanUtil.isTrue(searchAuthVO.getLiveRead())) {
      searchAuthVO.setLiveRead(true);
    }
    if (BooleanUtil.isTrue(authVO.getOutLendOut())
        || BooleanUtil.isTrue(searchAuthVO.getLendOut())) {
      searchAuthVO.setLendOut(true);
    }
    if (BooleanUtil.isTrue(authVO.getOutCopySend())
        || BooleanUtil.isTrue(searchAuthVO.getCopySend())) {
      searchAuthVO.setCopySend(true);
    }
    if (BooleanUtil.isTrue(authVO.getOutExcerpt())
        || BooleanUtil.isTrue(searchAuthVO.getExcerpt())) {
      searchAuthVO.setExcerpt(true);
    }
  }

  /**
   * 通用利用权限校验
   *
   * @param doc 档案
   * @param authVO 权限
   * @return
   */
  private void getOtherFondsAuth(
      SystemBO doc, ArchiveAuthScopeVO authVO, SearchAuthVO searchAuthVO) {
    // 档案全宗与当前用户全宗一致，无通用利用权限
    if (ObjectUtil.equals(doc.getFondsId(), SecurityUtil.getFondsId())) {
      return;
    }
    // 通用利用权限
    if (BooleanUtil.isTrue(authVO.getOtherOnlineBrowser())
        || BooleanUtil.isTrue(searchAuthVO.getOnlineBrowser())) {
      searchAuthVO.setOnlineBrowser(true);
    }
    if (BooleanUtil.isTrue(authVO.getOtherBrowserFile())
        || BooleanUtil.isTrue(searchAuthVO.getBrowserFile())) {
      searchAuthVO.setBrowserFile(true);
    }
    if (BooleanUtil.isTrue(authVO.getOtherOnlinePrint())
        || BooleanUtil.isTrue(searchAuthVO.getOnlinePrint())) {
      searchAuthVO.setOnlinePrint(true);
    }
    if (BooleanUtil.isTrue(authVO.getOtherDownload())
        || BooleanUtil.isTrue(searchAuthVO.getDownload())) {
      searchAuthVO.setDownload(true);
    }

    if (BooleanUtil.isTrue(authVO.getOtherDownloadSource())
        || BooleanUtil.isTrue(searchAuthVO.getDownloadSource())) {
      searchAuthVO.setDownloadSource(true);
    }
    if (BooleanUtil.isTrue(authVO.getOtherLiveRead())
        || BooleanUtil.isTrue(searchAuthVO.getLiveRead())) {
      searchAuthVO.setLiveRead(true);
    }
    if (BooleanUtil.isTrue(authVO.getOtherLendOut())
        || BooleanUtil.isTrue(searchAuthVO.getLendOut())) {
      searchAuthVO.setLendOut(true);
    }
    if (BooleanUtil.isTrue(authVO.getOtherCopySend())
        || BooleanUtil.isTrue(searchAuthVO.getCopySend())) {
      searchAuthVO.setCopySend(true);
    }
    if (BooleanUtil.isTrue(authVO.getOtherExcerpt())
        || BooleanUtil.isTrue(searchAuthVO.getExcerpt())) {
      searchAuthVO.setExcerpt(true);
    }
  }

  /**
   * 合并权限
   *
   * @param authVO1 权限1
   * @param authVO2 权限2
   * @return 新权限
   */
  public SearchAuthVO mergeAuth(SearchAuthVO authVO1, SearchAuthVO authVO2) {
    SearchAuthVO auth = new SearchAuthVO();
    // 判断当前用户是否有浏览权限，有直接返回
    SysUserVO userVO = sysUserSvc.view(SecurityUtil.getLoginUser().getSysUser().getId());
    if (ObjectUtil.isNotEmpty(userVO) && ObjectUtil.equals(userVO.getTextBrowsing(), 1)) {
      auth.setOnlineBrowser(true);
      auth.setBrowserFile(true);
    }
    // 通用利用权限
    if (BooleanUtil.isTrue(authVO1.getOnlineBrowser())
        || BooleanUtil.isTrue(authVO2.getOnlineBrowser())) {
      auth.setOnlineBrowser(true);
    }
    if (BooleanUtil.isTrue(authVO1.getBrowserFile())
        || BooleanUtil.isTrue(authVO2.getBrowserFile())) {
      auth.setBrowserFile(true);
    }
    if (BooleanUtil.isTrue(authVO1.getOnlinePrint())
        || BooleanUtil.isTrue(authVO2.getOnlinePrint())) {
      auth.setOnlinePrint(true);
    }
    if (BooleanUtil.isTrue(authVO1.getDownload()) || BooleanUtil.isTrue(authVO2.getDownload())) {
      auth.setDownload(true);
    }

    if (BooleanUtil.isTrue(authVO1.getDownloadSource())
        || BooleanUtil.isTrue(authVO2.getDownloadSource())) {
      auth.setDownloadSource(true);
    }
    if (BooleanUtil.isTrue(authVO1.getLiveRead()) || BooleanUtil.isTrue(authVO2.getLiveRead())) {
      auth.setLiveRead(true);
    }
    if (BooleanUtil.isTrue(authVO1.getLendOut()) || BooleanUtil.isTrue(authVO2.getLendOut())) {
      auth.setLendOut(true);
    }
    if (BooleanUtil.isTrue(authVO1.getCopySend()) || BooleanUtil.isTrue(authVO2.getCopySend())) {
      auth.setCopySend(true);
    }
    if (BooleanUtil.isTrue(authVO1.getExcerpt()) || BooleanUtil.isTrue(authVO2.getExcerpt())) {
      auth.setExcerpt(true);
    }
    return auth;
  }

  /**
   * 知悉范围内权限校验
   *
   * @param doc
   * @param authVO
   * @param useTypeEnum
   * @return
   */
  private boolean checkInDeptAuth(
      SystemBO doc, ArchiveAuthScopeVO authVO, UseTypeEnum useTypeEnum) {
    if (checkNotInDept(doc, authVO)) {
      return false;
    }

    switch (useTypeEnum) {
      case ONLINE_BROWSER:
        return BooleanUtil.isTrue(authVO.getOnlineBrowser());
      case BROWSER_FILE:
        return BooleanUtil.isTrue(authVO.getBrowserFile());
      case ONLINE_PRINT:
        return BooleanUtil.isTrue(authVO.getOnlinePrint());
      case DOWNLOAD:
        return BooleanUtil.isTrue(authVO.getDownload());
      case DOWNLOAD_SOURCE:
        return BooleanUtil.isTrue(authVO.getDownloadSource());
      case LIVE_READ:
        return BooleanUtil.isTrue(authVO.getLiveRead());
      case LEND_OUT:
        return BooleanUtil.isTrue(authVO.getLendOut());
      case COPY_SEND:
        return BooleanUtil.isTrue(authVO.getCopySend());
      case EXTRACT:
        return BooleanUtil.isTrue(authVO.getExcerpt());
    }
    return false;
  }

  /**
   * 不在知悉范围内
   *
   * @param doc
   * @param authVO
   * @return
   */
  private boolean checkNotInDept(SystemBO doc, ArchiveAuthScopeVO authVO) {
    // 知悉范围按部门划分，档案部门与当前用户部门不一致，返回无权限
    return ObjectUtil.notEqual(doc.getDepartmentId(), SecurityUtil.getSysUser().getDeptId());
  }

  /**
   * 知悉范围外权限
   *
   * @param doc 档案
   * @param authVO 权限
   * @param useTypeEnum 利用方式
   * @return
   */
  private boolean checkOutDeptAuth(
      SystemBO doc, ArchiveAuthScopeVO authVO, UseTypeEnum useTypeEnum) {
    // 知悉范围外
    // 全宗不一致，直接返回 无知悉范围外权限
    if (ObjectUtil.notEqual(doc.getFondsId(), SecurityUtil.getFondsId())) {
      return false;
    }
    // 知悉范围按部门划分, 档案部门与当前用户部门相同，无知悉范围外权限，直接返回无权限
    if (BooleanUtil.isTrue(authVO.getAuthDepartment())
        && ObjectUtil.equals(doc.getDepartmentId(), SecurityUtil.getSysUser().getDeptId())) {
      return false;
    }
    switch (useTypeEnum) {
      case ONLINE_BROWSER:
        return BooleanUtil.isTrue(authVO.getOutOnlineBrowser());
      case BROWSER_FILE:
        return BooleanUtil.isTrue(authVO.getOutBrowserFile());
      case ONLINE_PRINT:
        return BooleanUtil.isTrue(authVO.getOutOnlinePrint());
      case DOWNLOAD:
        return BooleanUtil.isTrue(authVO.getOutDownload());
      case DOWNLOAD_SOURCE:
        return BooleanUtil.isTrue(authVO.getOutDownloadSource());
      case LIVE_READ:
        return BooleanUtil.isTrue(authVO.getOutLiveRead());
      case LEND_OUT:
        return BooleanUtil.isTrue(authVO.getOutLendOut());
      case COPY_SEND:
        return BooleanUtil.isTrue(authVO.getOutCopySend());
      case EXTRACT:
        return BooleanUtil.isTrue(authVO.getOutExcerpt());
    }
    return false;
  }

  /**
   * 通用利用权限校验
   *
   * @param doc 档案
   * @param authVO 权限
   * @param useTypeEnum 利用方式
   * @return
   */
  private boolean checkOtherFondsAuth(
      SystemBO doc, ArchiveAuthScopeVO authVO, UseTypeEnum useTypeEnum) {
    // 档案全宗与当前用户全宗一致，无通用利用权限
    if (ObjectUtil.equals(doc.getFondsId(), SecurityUtil.getFondsId())) {
      return false;
    }
    // 通用利用权限
    switch (useTypeEnum) {
      case ONLINE_BROWSER:
        return BooleanUtil.isTrue(authVO.getOtherOnlineBrowser());
      case BROWSER_FILE:
        return BooleanUtil.isTrue(authVO.getOtherBrowserFile());
      case ONLINE_PRINT:
        return BooleanUtil.isTrue(authVO.getOtherOnlinePrint());
      case DOWNLOAD:
        return BooleanUtil.isTrue(authVO.getOtherDownload());
      case DOWNLOAD_SOURCE:
        return BooleanUtil.isTrue(authVO.getOtherDownloadSource());
      case LIVE_READ:
        return BooleanUtil.isTrue(authVO.getOtherLiveRead());
      case LEND_OUT:
        return BooleanUtil.isTrue(authVO.getOtherLendOut());
      case COPY_SEND:
        return BooleanUtil.isTrue(authVO.getOtherCopySend());
      case EXTRACT:
        return BooleanUtil.isTrue(authVO.getOtherExcerpt());
    }
    return false;
  }
}
